package com.le.tester.book.effectivejava3rdchinese.articlethirtyserven;


import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toMap;

/**
 * createTime：2022/8/22 14:56
 * description：固体，液体，气体阶段转换
 */
public enum Phase {

    /**
     * 使用EnumMap来代替数组的索引
     */
//    SOLID, LIQUID, GAS;
//
//    public enum Transition {
//        MELT, FREEZE, BOIL, CONDENSE, SUBLIME, DEPOSIT;
//        private static final Transition[][] TRANSITIONS = {
//                {null, MELT, SUBLIME},
//                {FREEZE, null, BOIL},
//                {DEPOSIT, CONDENSE, null}
//        };
//
//        public static Transition from(Phase from, Phase to) {
//
//            return TRANSITIONS[from.ordinal()][to.ordinal()];
//        }
//    }
    SOLID, LIQUID, GAS;

    public enum Transition {
        MELT(SOLID, LIQUID), FREEZE(LIQUID, SOLID),
        BOIL(LIQUID, GAS), CONDENSE(GAS, LIQUID),
        SUBLIME(SOLID, GAS), DEPOSIT(GAS, SOLID);

        private final Phase from;

        private final Phase to;

        Transition(Phase from, Phase to) {
            this.from = from;
            this.to = to;
        }

        //private static final Map<Phase, Map<Phase, Transition>> m = Stream.of(values()).collect(groupingBy(t -> t.from, () -> new EnumMap<>(Phase.class),
        //toMap(t ->[t.to](http:t.to),t ->t,(x,y)->y,()->new EnumMap<>(Phase .class))));

//        public static Transition from(Phase from, Phase to) {
//            return m.get(from).get(to);
//        }
    }


}
